#include <SGE.h>
#include "FrontendState.h"
#include "PlayState.h"

using namespace SGE;

GameContext gameContext;
GameState* currentState = nullptr;
NextState  nextState    = Gameplay;

void SGE_Initialize ()
{
	
}

void SGE_Terminate ()
{
	
}

bool SGE_Update (float deltaTime)
{
	if (nextState != None)
	{
		//Unload the current state
		if (currentState != nullptr)
		{
			currentState->Unload ();
			delete currentState;
		}

		//Change state
		switch (nextState)
		{
			case Frontend:
				currentState = new FrontendState (gameContext);
				break;

			case Gameplay:
				currentState = new PlayState (gameContext);
				break;
		}

		//Load new state
		currentState->Load ();
	}

	nextState = currentState->Update (deltaTime);

	if (nextState == Quit)
	{
		currentState->Unload ();
		delete currentState;

		return true;
	}

	return false;
}

void SGE_Render ()
{
	currentState->Render ();
}